Conditions | 1 |
Total Lines | 75 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React, { Component } from "react" |
||
11 | render() { |
||
12 | const { |
||
13 | title, |
||
14 | body = null, |
||
15 | localFile, |
||
16 | link, |
||
17 | metadata = false, |
||
18 | tags = [], |
||
19 | created = null, |
||
20 | } = this.props |
||
21 | |||
22 | const image = ( |
||
23 | <Img |
||
24 | fluid={{ |
||
25 | ...localFile.childImageSharp.fluid, |
||
26 | aspectRatio: 3 / 2, |
||
27 | }} |
||
28 | alt={title} |
||
29 | /> |
||
30 | ) |
||
31 | |||
32 | const absoluteUrlRegex = /^https?:\/\/|^\/\//i |
||
33 | |||
34 | return ( |
||
35 | <article className={"cardItem"}> |
||
36 | {absoluteUrlRegex.test(link) || ( |
||
37 | <Link to={link}> |
||
38 | <header> |
||
39 | <figure>{image}</figure> |
||
40 | </header> |
||
41 | |||
42 | <main className={"cardItem__summary"}> |
||
43 | <div className={"cardItem__heading"}> |
||
44 | <h3>{title}</h3> |
||
45 | </div> |
||
46 | |||
47 | {body && <div dangerouslySetInnerHTML={{ __html: body }}></div>} |
||
48 | </main> |
||
49 | </Link> |
||
50 | )} |
||
51 | |||
52 | {absoluteUrlRegex.test(link) && ( |
||
53 | <a href={link} target="_blank" rel="noopener noreferrer"> |
||
54 | <header> |
||
55 | <figure>{image}</figure> |
||
56 | </header> |
||
57 | |||
58 | <main className={"cardItem__summary"}> |
||
59 | <div className={"cardItem__heading"}> |
||
60 | <h3>{title}</h3> |
||
61 | </div> |
||
62 | |||
63 | {body && <div dangerouslySetInnerHTML={{ __html: body }}></div>} |
||
64 | </main> |
||
65 | </a> |
||
66 | )} |
||
67 | |||
68 | {metadata && ( |
||
69 | <footer className={"cardItem__footer article__tags"}> |
||
70 | <span className={"datetime"}> |
||
71 | <i className={"fa fa-clock-o"} aria-hidden="true"></i> {created} |
||
72 | </span> |
||
73 | {tags.length > 0 && ( |
||
74 | <span className={"tag__wrapper"}> |
||
75 | <i className={"fa fa-tags"} aria-hidden="true"></i>{" "} |
||
76 | {tags.map(({ path, name }, i) => ( |
||
77 | <Link to={path.alias} key={i}> |
||
78 | <span className={"tag__label"}>#{name}</span> |
||
79 | </Link> |
||
80 | ))} |
||
81 | </span> |
||
82 | )} |
||
83 | </footer> |
||
84 | )} |
||
85 | </article> |
||
86 | ) |
||
211 |